<?php
namespace app\command;

use app\model\OrdersModel;
use app\model\StatisticsModel;
use think\console\Command;
use think\console\Input;
use think\console\Output;

class StatisticsWeb extends Command
{
    protected function configure()
    {
        $this->setName('统计脚本')
            ->setDescription('批量处理统计数据');
    }

    protected function execute(Input $input, Output $output)
    {
        // 执行你的脚本任务代码
        $statisticsModel = new StatisticsModel();
        $id = $statisticsModel->where("date", "=", date("Ymd"))->value("id");
        $date =date("Y-m-d");
        $pv = $statisticsModel->getPv();
        $uv = $statisticsModel->getUv();
        $todayLogin = $statisticsModel->getTodayLogin();
        $todayRegister = $statisticsModel->getTodayRegister();
        $pv = $pv ? $pv : 0;
        $uv = $uv ? $uv : 0;
        $todayLogin = $todayLogin ? $todayLogin : 0;
        $todayRegister = $todayRegister ? $todayRegister : 0;

        if($id){
           $statisticsModel->where("id", "=", $id)->update([
                "date"=>$date,
                "pv"=>$pv,
                "uv"=>$uv,
                "today_login"=>$todayLogin,
                "today_register"=>$todayRegister,
            ]);
        }else{
              $statisticsModel->insert([
                  "date"=>$date,
                  "pv"=>$pv,
                  "uv"=>$uv,
                  "today_login"=>$todayLogin,
                  "today_register"=>$todayRegister,
            ]);
        }
    }
}